package com.dailywork.basepro.comclass;

import java.util.Objects;

public class SelfClassDef {
    public static void main(String[] args) {
        SelfClassDef selfClassDef1 = new SelfClassDef();
        selfClassDef1.name = "dx";
        selfClassDef1.age = "dx1";

        SelfClassDef selfClassDef2 = new SelfClassDef();
        selfClassDef2.name = "dx";
        selfClassDef2.age = "dx1";

        System.out.println(selfClassDef1.equals(selfClassDef2));
        System.out.println(selfClassDef1.toString());
    }

    private String name;
    private String age;

    @Override
    public boolean equals(Object obj) {
        if (Objects.isNull(obj)) {
            return Boolean.FALSE;
        }

        if (this == obj) {
            return Boolean.TRUE;
        }
        // getclass返回当对象的类
        if (getClass() != obj.getClass()) {
            return Boolean.FALSE;
        }
        // 包含基类和派生类
        if (!(obj instanceof SelfClassDef)) {
            return Boolean.FALSE;
        }
        SelfClassDef other = (SelfClassDef) obj;
        return Objects.equals(name, other.name) && Objects.equals(age, other.age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return getClass().getName() + "[name: " + name + ";age: " + age + "]";
    }
}
